﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExitEventApp
{
    public class ExitEvent
    {
        //fields
        private String eventName;
        private Client client;
        private DataHelper dh;

        /*Constructor*/
        public ExitEvent(String name, long clientId,DataHelper d)
        {
            this.dh = d;
            this.eventName = name;
            client = dh.getClient(clientId);
        }
        
        /*returns the client of the event*/
        public Client getClient(long clientId)
        {
            return client;
        }

        /* it will set the Date of the last exit to the current data and it will change the status of the client
         * it return true if the change of status succeeds, or false otherwise*/
        public bool exitEvent(Client c)
        {
            c.Status = "out";
            c.LastExit = DateTime.Now;
            if (dh.changeStatusClient(c.ClientId, c.LastExit) > -1)
            { return true; }
            return false;
        }

        /* it sets the balance to zero and also changes the balance in the database
         * it returns true if the change of the balance succeeds, or false otherwise*/
        public bool sendBalance(Client c)
        {
            if (c.Balance > 0 && DateTime.Today.Subtract(c.LastExit).TotalDays >= 2 && c.LastExit<Convert.ToDateTime("01-01-2020"))
            {
                c.Balance = 0;
                //dh.changeBalanceClient(c.ClientId);
                return true;
            }
            return false;
        }
    }
}
